package client.output.gui.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;

import client.constants.output.gui.IGuiCaptions;
import client.output.gui.ChatWindow;

public abstract class AChatController implements IChatController,
		ActionListener {

	private Map<String, Integer> actionMap;
	protected ChatWindow window;

	public AChatController() {
		this.actionMap = new HashMap<String, Integer>();

		initActionMap();
	}

	private void initActionMap() {
		actionMap.put(IGuiCaptions.BTN_SEND, Integer
				.valueOf(IGuiCaptions.INDEX_BTN_SEND));
	}

	@Override
	public void actionPerformed(ActionEvent ev) {
		int evCode = actionMap.get(ev.getActionCommand()).intValue();

		switch (evCode) {
		case IGuiCaptions.INDEX_BTN_SEND:
			handleSend();
		}
	}

	public void setWindow(ChatWindow window) {
		this.window = window;
	}
	
	protected ChatWindow getWindow() {
		return this.window;
	}
	
	public void writeMessage(String message) {
		window.writeMessage(message);
	}
}
